/**
 * 
 */
package org.ranch.web.propertyeditors;

import org.apache.commons.lang.StringUtils;
import org.ranch.api.service.FarmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author Jmpango
 *
 */
@Component("farmPropertyEditor")
public class FarmPropertyEditor extends BasePropertyEditor{

    @Autowired
    FarmService farmService;
    
    @Override
    public void setAsText(String text) throws IllegalArgumentException {
	if (StringUtils.isNotBlank(text) && StringUtils.isNotEmpty(text)) {
	    if (StringUtils.equalsIgnoreCase("none", text)) {
		super.setValue(null);
	    } else {
		super.setValue(farmService.getFarmById(text));
	    }
	} else {
	    super.setAsText(text);
	}
    }
}
